package com.todo.event.activity.application.handler.activityrule;

import com.todo.event.activity.application.core.frequency.FrequencyHelper;
import com.todo.event.activity.application.entity.context.ActivityRuleContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author azhebuxing
 * @date 2025/1/13 15:16
 * @description
 */
@Slf4j
@Component
public class FrequencyHandle extends AbstractActivityRuleHandle {

    @Resource
    private FrequencyHelper frequencyHelper;

    @Override
    protected String ruleName() {
        return "Frequency";
    }

    @Override
    protected boolean doRuleHandle(ActivityRuleContext context) {
        Boolean recordCount = frequencyHelper.checkRecordCount(context.getActivityId(), context.getUserId(), context.getOperateTime());
        return recordCount;
    }

    @Override
    protected boolean ruleMatch(ActivityRuleContext context) {
        if (context == null || context.getFrequency() != null) {
            return true;
        }
        return false;
    }
}
